using System;
using System.Runtime.InteropServices;
using UnityEngine;

public class UserPrefs : MonoBehaviour
{
	public static bool getBool(string key, bool defaultValue = false)
	{
		if (PlayerPrefs.HasKey(key))
		{
			if (PlayerPrefs.GetInt(key) == 0)
			{
				return false;
			}
			return true;
		}
		return defaultValue;
	}

	public static void setBool(string key, bool val)
	{
		if (val)
		{
			PlayerPrefs.SetInt(key, 1);
		}
		else
		{
			PlayerPrefs.SetInt(key, 0);
		}
	}

	public static int getInt(string key, int defaultValue = -1)
	{
		if (PlayerPrefs.HasKey(key))
		{
			return PlayerPrefs.GetInt(key);
		}
		return defaultValue;
	}

	public static void setInt(string key, int val)
	{
		PlayerPrefs.SetInt(key, val);
	}

	public static float getFloat(string key, float defaultValue = -1f)
	{
		if (PlayerPrefs.HasKey(key))
		{
			return PlayerPrefs.GetFloat(key);
		}
		return defaultValue;
	}

	public static void setFloat(string key, float val)
	{
		PlayerPrefs.SetFloat(key, val);
	}

	public static void setString(string key, string sValue)
	{
		PlayerPrefs.SetString(key, sValue);
	}

	public static string getString(string key, string defaultValue = "")
	{
		if (PlayerPrefs.HasKey(key))
		{
			return PlayerPrefs.GetString(key);
		}
		return defaultValue;
	}

	public static void setDate(string key, DateTime date)
	{
		PlayerPrefs.SetString(key, date.ToString());
	}

	public static DateTime getDate(string key, [Optional] DateTime defaultDate)
	{
		if (PlayerPrefs.HasKey(key))
		{
			return DateTime.Parse(PlayerPrefs.GetString(key));
		}
		return defaultDate;
	}

	public static void Save()
	{
		PlayerPrefs.Save();
	}

	public static void DeleteKey(string key)
	{
		if (PlayerPrefs.HasKey(key))
		{
			PlayerPrefs.DeleteKey(key);
		}
	}

	public static bool HasKey(string key)
	{
		return PlayerPrefs.HasKey(key);
	}
}
